import request from '@/utils/request'

// 查询订单生成列表
export function listOrdergenerate(query) {
  return request({
    url: '/ordergenerate/ordergenerate/list',
    method: 'get',
    params: query
  })
}

// 查询订单生成详细
export function getOrdergenerate(planNo) {
  return request({
    url: '/ordergenerate/ordergenerate/' + planNo,
    method: 'get'
  })
}

// 新增订单生成
export function addOrdergenerate(data) {
  return request({
    url: '/ordergenerate/ordergenerate',
    method: 'post',
    data: data
  })
}

// 修改订单生成
export function updateOrdergenerate(data) {
  return request({
    url: '/ordergenerate/ordergenerate',
    method: 'put',
    data: data
  })
}

// 删除订单生成
export function delOrdergenerate(planNo) {
  return request({
    url: '/ordergenerate/ordergenerate/' + planNo,
    method: 'delete'
  })
}

//获取满足条件供货商列表
export function getSupplierList(data) {
  return request({
    url: '/ordergenerate/ordergenerate/suppliers',
    method: 'post',
    data: data
  })
}

//获取满足条件的货品列表
export function getProducts(data) {
  return request({
    url: '/rawproduct/rawproduct/listByName',
    method: 'post',
    data: data
  })
}

//生成随机订单编号
export function generateOrderNumber() {
  // 定义字符集，可以根据需要调整
  const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
  let orderNumber = '';
  for (let i = 0; i < 10; i++) {
    const randomIndex = Math.floor(Math.random() * chars.length);
    orderNumber += chars[randomIndex];
  }
  return orderNumber;
}
